#ifndef PRAXIS_UI_RECIPE_MANAGER_CTRL_H_
#define PRAXIS_UI_RECIPE_MANAGER_CTRL_H_

#include <praxis/praxis_export.h>
#include <windows.h>

#include <memory>
#include <string>

namespace praxis {
// Forward-declarations to avoid including heavy headers.
// This is a key benefit of PIMPL.
class CSchemaService;

/**
 * @class RecipeManagerCtrl
 * @brief Manages the UI for loading, displaying, and editing recipes.
 *
 * This class provides a complete UI control for recipe management. It is
 * implemented using the PIMPL idiom to hide all Win32 handles and
 * implementation details from the header file, providing a stable ABI and
 * reducing compilation dependencies.
 */
class PRAXIS_API RecipeManagerCtrl {
 public:
  /**
   * @brief Constructs the RecipeManagerCtrl.
   *
   * @param h_instance The application instance handle.
   * @param h_parent The parent window handle.
   */
  RecipeManagerCtrl(HINSTANCE h_instance, HWND h_parent);

  /**
   * @brief Destructor. Must be defined in the .cc file for std::unique_ptr
   *        with an incomplete type to work correctly.
   */
  ~RecipeManagerCtrl();

  // Disable copy and move operations to prevent slicing and ownership issues.
  RecipeManagerCtrl(const RecipeManagerCtrl&) = delete;
  RecipeManagerCtrl& operator=(const RecipeManagerCtrl&) = delete;

  /**
   * @brief Creates the UI controls for the manager.
   *
   * @param x The x-coordinate of the control's top-left corner.
   * @param y The y-coordinate of the control's top-left corner.
   * @param width The width of the control.
   * @param height The height of the control.
   * @param control_id The base ID for the created controls.
   */
  void Create(int x, int y, int width, int height, int control_id);

  /**
   * @brief Sets the schema service used to validate and interpret recipes.
   *
   * @param schema_service A pointer to a valid CSchemaService instance.
   *        The RecipeManagerCtrl does not take ownership of this pointer.
   */
  void SetSchemaService(CSchemaService* schema_service);

  /**
   * @brief Loads all recipes from a specified directory path.
   *
   * @param directory_path The path to the folder containing recipe .json files.
   */
  void LoadRecipes(const std::wstring& directory_path);

  /**
   * @brief Handles notification messages from parent window.
   *
   * @param msg A pointer to the NMHDR structure.
   * @return LRESULT The result of the message processing.
   */
  LRESULT HandleNotify(LPARAM l_param);

  /**
   * @brief Resizes the control and its children to fit new dimensions.
   * NEW: Handles window resizing.
   */
  void Resize(int x, int y, int width, int height);

  /**
   * @brief Saves any changes made in the interactive editor to the file.
   * NEW: Handles saving modified recipe.
   */
  void SaveChanges();

 private:
  // The forward-declared implementation class.
  // All private members and methods are hidden inside this struct.
  struct Impl;
  std::unique_ptr<Impl> impl_;
};
}  // namespace praxis

#endif  // PRAXIS_UI_RECIPE_MANAGER_CTRL_H_
